package com.hua.springCloud.controller;

import com.hua.springCloud.entities.CommonResult;
import com.hua.springCloud.entities.Payment;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.RestTemplate;

@RestController
public class ConsumerController {

//    private static final String URL="http://localhost:8001";
    private static final String URL="http://CLOUD-PAYMENT-SERVICE";


    @Autowired
    private RestTemplate restTemplate;

    @GetMapping("/consumer/create") //用get访问别的post API 要在post请求的参数加@RequstBody 否则参数加不进去
    public CommonResult getInfo(Payment payment){
        return restTemplate.postForObject(URL+"/payment/create",payment,CommonResult.class);
    }
    @GetMapping("/consumer/get/{id}")
    public CommonResult getInfo1(Payment payment,@PathVariable("id") Long id){
        return restTemplate.getForObject(URL+"/payment/get/"+id,CommonResult.class);
    }
    @GetMapping("/consumer/info/forEntities")
    public CommonResult getInfo1(Payment payment){
       return restTemplate.postForEntity(URL+"/info/forEntities",payment,CommonResult.class).getBody();
    }
    @GetMapping("/consumer/getPaymentPort")
    public String getPort(){
        return restTemplate.getForObject(URL+"/getPaymentPort",String.class);
    }

    @GetMapping("/consumer/zipkin")
    public String viewZipkin(){
        restTemplate.getForObject(URL+"/payment/zipkin",String.class);
        return "我爱你80";
    }
}
